﻿// 1.1.6.18. Write a program that reads a positive integer number N (N < 20) from the console and outputs in the console
// the numbers from 1 to N*N arranged as a spiral. Example: for N = 4 ->  1  2  3 4
//                                                                       12 13 14 5
//                                                                       11 16 15 6
//                                                                       10  9  8 7

using System;

class SpiralMatrix
{
    static void Main()
    {
        Begin:
        int userInput = int.Parse(Console.ReadLine());
        int[,] matrixToFill = new int[userInput, userInput];
        int numberForFill = 1;

        int row = 0;
        int col = 0;
        int endRightCol = userInput - 1;
        int endDownRow = userInput - 1;
        int endLeftCol = 0;
        int endUpRow = 1;

        while (true)
        {
            for (col = col; col <= endRightCol; col++)  // right
            {
                matrixToFill[row, col] = numberForFill;
                numberForFill++;
            }
            if (numberForFill > userInput * userInput)
            {
                break;
            }
            col--;
            endRightCol--;
            row++;
            for (row = row; row <= endDownRow; row++)   // down
            {
                matrixToFill[row, col] = numberForFill;
                numberForFill++;
            }
            row--;
            endDownRow--;
            col--;
            for (col = col; col >= endLeftCol; col--)   // left
            {
                matrixToFill[row, col] = numberForFill;
                numberForFill++;
            }
            if (numberForFill > userInput * userInput)
            {
                break;
            }
            col++;
            endLeftCol++;
            row--;
            for (row = row; row >= endUpRow; row--) // up
            {
                matrixToFill[row, col] = numberForFill;
                numberForFill++;
            }
            row++;
            endUpRow++;
            col++;
        }

        for (int i = 0; i <= userInput - 1; i++)
        {
            for (int j = 0; j <= userInput - 1; j++)
            {
                Console.Write("{0, 3}", matrixToFill[i, j]);
            }
            Console.WriteLine();
        }
        goto Begin;
    }
}